package com.swpu.cbg.cnshop.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.Button;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.swpu.cbg.cnshop.R;
import com.swpu.cbg.cnshop.bean.Favorites;
import com.swpu.cbg.cnshop.bean.Ware;

import java.util.List;


public class FavoriteAdatper extends BaseAdapter<Favorites,BaseViewHolder> implements View.OnClickListener{

    private onItemHandleListener mListener;
    private int position;
    public FavoriteAdatper(Context mContext, List<Favorites> mDatas, int itemViewID) {
        super(mContext, mDatas, itemViewID);
    }

    public void setmListener(onItemHandleListener mListener) {
        this.mListener = mListener;
    }

    @Override
    void bindData(BaseViewHolder holder, int position) {
        Ware wares = mDatas.get(position).getWares();
        SimpleDraweeView draweeView = (SimpleDraweeView) holder.getView(R.id.drawee_view);
        draweeView.setImageURI(Uri.parse(wares.getImgUrl()));
        holder.getTextView(R.id.text_title).setText(wares.getName());
        holder.getTextView(R.id.text_price).setText("￥ " + wares.getPrice());

        Button buttonRemove = holder.getButton(R.id.btn_remove);
        Button buttonLike = holder.getButton(R.id.btn_like);
        this.position = position;
        buttonRemove.setOnClickListener(this);

        buttonLike.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(mListener!=null){
            switch (v.getId()){
                case R.id.btn_remove:
                    mListener.removeWare(v,mDatas.get(position).getWares());
                    break;

                case R.id.btn_like:
                    mListener.likeWare(v,mDatas.get(position).getWares());
                    break;
            }
        }
    }


    public interface onItemHandleListener{
        void removeWare(View view,Ware ware);
        void likeWare(View view,Ware ware);
    }
}
